<?php

/**
 * AuthController
 *
 * @author Maodo DIOP <dmaodo@gmail.com>
 * @version
 */

require_once 'Zend/Controller/Action.php';
require_once 'Zend/Auth.php';
require_once 'Zend/Auth/Adapter/DbTable.php';

class Admin_PointgmvController extends Zend_Controller_Action {

	public function indexAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		$pointgmv = new Admin_Model_DbTable_Pointgmv();
		$res = $pointgmv->getAllPointgmv();
		$resultat = Zend_Json :: encode($res);
		//$this->_response->setHeader('Content-Type', 'text/x-json');
		$this->_response->setBody($resultat);
	}

	public function addAction() {
		$this->view->title = "Ajouter Point GMV";
		$this->view->headTitle($this->view->title);

		$form = new Admin_Form_Pointgmv();

		$form->submit->setLabel('Ajouter');
		$this->view->form = $form;

		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {

				$latitude = $form->getValue('latitude');
				$longitude = $form->getValue('longitude');
				$pointgmvprec = $form->getValue('pointgmvprec');
				$pointgmv = new Admin_Model_DbTable_Pointgmv();

				$pointgmv->addPointgmv($latitude,$longitude,$pointgmvprec);
				$this->_helper->redirector('index');
			} else {
				$form->populate($formData);
			}
		}
	}


	public function addijAction()
	{
		 

		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		if ($this->getRequest()->isPost()) {
			$i = $this->getRequest()->getPost('i');
			$j =$this->getRequest()->getPost('j');
			$pointgmv = new Admin_Model_DbTable_Pointgmv();
			$pointgmv->addPointgmvIJ($i,$j);
			$res[] = "bon";
				
		}
		else {
			$res[] = "Pas de post";
		}
		$resultat = Zend_Json :: encode($res);
		$this->_response->setHeader('Content-Type', 'text/x-json');
		$this->_response->setBody($resultat);



	}

	public function editAction() {
		$form = new Admin_Form_Pointgmv() ;

		$form->submit->setLabel('Enregistrer');
		$this->view->form = $form;

		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {

				$idpointgmv = (int)$this->_getParam('idpointgmv');;
				$latitude = $form->getValue('latitude');
				$longitude = $form->getValue('longitude');
				$pointgmvprec = $form->getValue('pointgmvprec');
				$pointgmv = new Admin_Model_DbTable_Pointgmv();

				$pointgmv = new Admin_Model_DbTable_Pointgmv();
				$pointgmv->updatePointgmv($idpointgmv, $latitude, $longitude, $pointgmvprec);
				$res = array();
				$res = $pointgmv->getPointgmv($idpointgmv);
				$this->_redirect('/admin/pointgmv/index');
			} else {
				$form->populate($formData);
			}
		} else {
			//Si le formulaire n'est pas encore post�
			//Recuperer la valeur de l'objet � editer
			$idpointgmv = $this->_request->getParam('idpointgmv', 0);
			if ($idpointgmv > 0) {
				$pointgmv = new Admin_Model_DbTable_Pointgmv();
				$form->populate($pointgmv->getPointgmv($idpointgmv));
			}
		}
	}


	public function deleteAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();

		$idpointgmv = $this->_getParam('idpointgmv', 0);
		$pointgmv = new Admin_Model_DbTable_Pointgmv();
		$pointgmv->deletePointgmv($idpointgmv);
		$this->_redirect('/pointgmv/index');
	}
	
	

	public function allpointgmvAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		$pointgmv = new Admin_Model_DbTable_Pointgmv();
		$res = $pointgmv->getAllPointgmv();
		$resultat = Zend_Json :: encode($res);
		$this->_response->setHeader('Content-Type', 'text/x-json');
		$this->_response->setBody($resultat);
	}
}

